package database

import (
	"gitee.com/sansaniot/ssiot-core/facade/runtime"
	"ssnotify/internal/notify/models"
)

// 仅创建、AutoMigrate会修改已存在表字段类型(-- 写好新增表的标签信息 --)
func Migrate() {
	// 获取db
	db := runtime.Runtime.GetDbByKey("db")
	if db == nil {
		return
	}
	if !db.Migrator().HasTable(&models.NotifySender{}) {
		_ = db.AutoMigrate(&models.NotifySender{})
		initRows := make([]models.NotifySender, 0)
		// 短信
		initRows = append(initRows, models.NotifySender{
			Id:    "sms.accessKey",
			Title: "短信accessKey",
		})
		initRows = append(initRows, models.NotifySender{
			Id:    "sms.accessSecret",
			Title: "短信accessSecret",
		})
		initRows = append(initRows, models.NotifySender{
			Id:    "sms.signName",
			Title: "短信签名",
		})
		// 邮件
		initRows = append(initRows, models.NotifySender{
			Id:    "email.host",
			Title: "邮件服务器",
		})
		initRows = append(initRows, models.NotifySender{
			Id:    "email.port",
			Title: "邮件服务器端口",
		})
		initRows = append(initRows, models.NotifySender{
			Id:    "email.username",
			Title: "邮箱账号",
		})
		initRows = append(initRows, models.NotifySender{
			Id:    "email.password",
			Title: "邮箱密码",
		})
		db.Model(&initRows).Create(&initRows)
	}
}
